﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
//
using PerceptiveMCAPI;
using PerceptiveMCAPI.Types;
//
namespace PerceptiveMCAPI_Test
{
   public partial class show_listWebhooks : System.Web.UI.UserControl
   {
      public void Display( listWebhooksOutput output )
      {
         this.Visible = true;
         litList.Text = output.inputParms.id;
         //
         gvListWebhooks.DataSource = output.result;
         gvListWebhooks.DataBind();
      }
      // --------------------------------------------------------
      protected string FormatActions( object reqActions )
      {
         StringBuilder sb = new StringBuilder();
         string actionString = "";

         Dictionary<EnumValues.listWebhookActions, bool> actions
            = (Dictionary<EnumValues.listWebhookActions, bool>)reqActions;
         if ( actions.Count > 0 )
         {
            foreach ( KeyValuePair<EnumValues.listWebhookActions, bool> action in actions )
            {
               sb.AppendFormat( "{0}=>{1}<br />", action.Key, action.Value );
            }
            actionString = sb.ToString( 0, sb.Length - 6 );
         }
         //
         return actionString;
      }

      protected string FormatSources( object reqSource )
      {
         StringBuilder sb = new StringBuilder();
         string sourceString = "";

         Dictionary<EnumValues.listWebhookSources, bool> sources
            = (Dictionary<EnumValues.listWebhookSources, bool>)reqSource;

         if ( sources.Count > 0 )
         {
            foreach ( KeyValuePair<EnumValues.listWebhookSources, bool> source in sources )
            {
               sb.AppendFormat( "{0}=>{1}<br />", source.Key, source.Value );
            }
            sourceString = sb.ToString( 0, sb.Length - 6 );
         }
         return sourceString;
      }
   }
}